@use "../01-utils/tokens" as *;

:root {
  --header-height: var(--base-space-16);
  --focus-ring: 0px 0px 0px 3px var(--color-neutral-100);
}

html {
  color-scheme: light dark;
  height: 100vh; // fallback
  height: 100dvh;

  @media (width > 450px) {
    scrollbar-gutter: stable;
  }
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  font-family: var(--font-family);
  margin: 0;
}

::selection {
  --bg-color: light-dark(
    var(--color-background-strong-inverse),
    var(--color-background-strong)
  );
  --text-color: light-dark(
    var(--color-foreground-inverse),
    var(--color-foreground)
  );

  background-color: var(--bg-color);
  color: var(--text-color);
}

:focus-visible {
  outline: 2px solid var(--color-action);
}

input:focus-visible {
  outline: none;
}

a {
  color: var(--color-action);
  text-decoration: none;

  &:hover,
  &:focus-visible {
    text-decoration: underline;
    text-underline-offset: 4px;
  }
}

abbr {
  text-decoration: none;
}

main,
iframe,
img,
svg {
  display: block;
}

a[href^="https"] {
  svg:is([data-icon="external"]) {
    display: inline-block;
    vertical-align: middle;
    width: 1em;
    height: 1em;
    margin-left: 0.2em;
    transform: translateY(-0.1em);
  }
}

.page {
  flex: 1;
  padding: var(--base-space-8) var(--page-padding-x);
}

pre {
  overflow-x: auto;
}

.page table {
  border-collapse: separate;
  border-spacing: 0;
  max-inline-size: 100%;
  width: 100%;
}

.page th {
  background-color: var(--color-bg-alt);
  border-block-color: var(--color-border);
  border-inline-color: transparent;
  border-style: solid;
  border-width: 1px;
  font-weight: 700;

  &:first-of-type {
    border-start-start-radius: var(--base-space-2);
    border-inline-start-color: var(--color-border);
  }

  &:last-of-type {
    border-start-end-radius: var(--base-space-2);
    border-inline-end-color: var(--color-border);
  }
}

.page td {
  border-block-end-color: var(--color-border);
  border-block-start-color: transparent;
  border-inline-color: transparent;
  border-style: solid;
  border-width: 1px;
  font-size: var(--font-size-sm);

  &:first-of-type {
    border-inline-start-color: var(--color-border);
  }

  &:last-of-type {
    border-inline-end-color: var(--color-border);
  }
}

.page tr:last-of-type {
  td:first-of-type {
    border-end-start-radius: var(--base-space-2);
  }
  td:last-of-type {
    border-end-end-radius: var(--base-space-2);
  }
}

.page th,
.page td {
  padding: var(--base-space-3) var(--base-space-4);
}

.link-button {
  display: inline-flex;
  padding-block: var(--base-space-3);
}

// md anchors
.md-content {
  h1,
  h2,
  h3,
  h4,
  h5,
  h6:has(a[tabindex="-1"]) {
    position: relative;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    a[tabindex="-1"] {
      align-items: center;
      display: flex;
      height: 1em;
      justify-content: center;
      left: -2.5rem;
      opacity: 0;
      position: absolute;
      text-decoration: none;
      transition: opacity 100ms linear;
      width: 2.5rem;

      &::after {
        content: "#";
        font-size: var(--font-size-xl);
      }

      &:focus {
        opacity: 1;
      }
    }

    &:hover a[tabindex="-1"] {
      opacity: 1;
    }
  }
}

// Code block
.astro-code {
  background-color: var(--color-background-strong-inverse) !important;
  border-radius: var(--base-space-3);
  color: var(--color-foreground-inverse) !important;
  font-family: var(--font-monospace);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  min-width: 65ch;
  padding: var(--base-space-4) !important;
  width: 100%;
}

// Table of Contents
.md-content {
  $toc-breakpoint-m: 1050px;

  .toc {
    box-sizing: border-box;
    font-size: var(--font-size-xs);
    padding-block-start: var(--base-space-3);

    @media (width >= $toc-breakpoint-m) {
      position: fixed;
      top: var(--base-space-12);
      right: var(--base-space-4);
      width: 20rem;
    }

    h4#contents {
      font-size: var(--font-size-md);
      margin: 0 0 var(--base-space-3) 0;
    }

    ol {
      margin: 0;
      padding: 0;

      @media (width >= $toc-breakpoint-m) {
        ol {
          li {
            overflow: hidden;
            height: 0;
            transition: height 100ms cubic-bezier(0.33, 1, 0.68, 1);
          }

          &:has(a[aria-current]) li {
            height: 1.25rem;
          }
        }
      }
    }

    li {
      list-style: none;
      line-height: 1;
      margin: 0;
      padding: 0;

      & > ol > li > a {
        padding-inline-start: var(--base-space-8);
      }
    }

    a {
      border-inline-start: 1px solid var(--color-border);
      color: var(--color-text-subdued);
      display: block;
      padding-block: var(--base-space-1);
      padding-inline-end: var(--base-space-1);
      padding-inline-start: var(--base-space-4);
      overflow: hidden;
      text-decoration: none;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 100%;

      &:hover {
        border-inline-start-color: var(--color-action-subdued);
        color: var(--color-action-subdued);
      }

      &[aria-current] {
        color: var(--color-action);
        border-inline-start-color: var(--color-action);

        @media (width >= $toc-breakpoint-m) {
          ~ ol li {
            height: 1.25rem;
          }
        }
      }
    }

    // hierarchy
    > ol > li > a {
      font-size: var(--font-size-sm);
    }

    > ol > li > ol > li > a {
      font-size: var(--font-size-xs);
    }
  }
}
